Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FiberRef #1822

Closed
wants to merge 1 commit into from
Closed

FiberRef #1822

wants to merge 1 commit into from

Conversation

RaasAhsan
Copy link

Follow up to #1393

@RaasAhsan RaasAhsan requested a review from kubukoz March 26, 2021 17:15
* Divorces the current reference from parent fiber and
* sets a new reference for the duration of `fa` evaluation.
*/
def locally(fa: F[A]): F[A]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't that be def locally[B](fb: F[B]): F[B]? with a new method level type-parameter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should yeah

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had a similar case in Resource once... 0bd5660 (#1368)

local <- FiberLocal[Ref[IO, A]](ref)
} yield new FiberRef[IO, A] {
override def locally(fa: IO[A]): IO[A] = {
val acquire = local.get.product(Ref.of[IO, A](default)).flatTap {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random thought, should this use default or the current value in the "outer" scope as the initial value instead?

Also, we can save a lot of typing by doing local.get first and flatMapping over that, but I don't know about the performance.

* Divorces the current reference from parent fiber and
* sets a new reference for the duration of `fa` evaluation.
*/
def locally(fa: F[A]): F[A]
Copy link
Member

@kubukoz kubukoz Apr 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using locals (a copy of this PR) to get a separate scope for every test in a weaver suite, but:

  • using a normal IOLocal is insufficient, as I want to share the scope between fibers forked within a single test
  • using a FiberRef like here works as long as I remember to isolate the scope. Problem is, I don't expose the locals because they're hidden behind some interface (i.e. a tagless algebra). A way to do locally with all FiberRefs in existence would be really cool. So pretty much the IO.clearLocals you mentioned in Fiber locals #1393, but with knowledge of FiberRef (just clearing the local doesn't cut it for a Ref because it can be the same value if we're at the start of a test).

with knowledge of FiberRef

this is probably the worst part.

@vasilmkd
Copy link
Member

vasilmkd commented Jun 18, 2021

Not sure what the status is of this PR. Is there a consensus on how to continue here?

Feel free to remove it from the milestone if you think it's not going to make it.

@vasilmkd vasilmkd added this to the 3.2.0 milestone Jun 18, 2021
@djspiewak
Copy link
Member

Any consensus on this? It seems like locally does need some adjustment at the least.

@djspiewak djspiewak removed this from the 3.2.0 milestone Jul 22, 2021
@djspiewak djspiewak closed this Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants